Skip to content

Conversation

wjrm500
Copy link
Collaborator

@wjrm500 wjrm500 commented Jul 10, 2025

WIP - Please note that the code and PR description have been AI-generated as a rapid prototype for testing and validation

Description

We encountered a bug where users could skip pages in forms when selecting multiple checkboxes. This happened because the conditions that control page navigation were stored in the wrong order. When a user selected both "feasibility study" and "call for projects" checkboxes, the system would jump directly to the "call for projects" page and skip the "feasibility study" page entirely, because the "call for projects" condition was evaluated first in the list.

Our fix automatically sorts the navigation conditions to match the order of the checkboxes that trigger them. When a form is saved, the system now looks at the order of options in the checkbox field and reorders the corresponding conditions to match. This ensures that if "feasibility study" appears before "call for projects" in the checkbox list, its condition will also be evaluated first, preventing pages from being skipped.

This approach has some limitations. It only works for forms that use checkboxes or radio buttons to control navigation flow. If conditions are based on other types of form fields or complex logic, the sorting may not work as expected. Additionally, the fix assumes that the visual order of options should match the navigation order, which may not always be the desired behavior for all forms.

Testing

  • Create a test form in the Designer with a page containing checkboxes (e.g., milestone options like "Consulting community", "Feasibility study", "Call for projects")
  • Add target pages for each checkbox option and create conditions that link to these pages
  • Deliberately create conditions in the wrong order when setting up page navigation (e.g., add "Call for projects" condition before "Feasibility study" condition)
  • Save the form - the fix should automatically reorder the conditions to match the checkbox order
  • Preview the form and select multiple checkboxes, then navigate through the form to verify all pages are visited in the correct sequence (no pages should be skipped)
  • Optional: Download the form JSON and check that the next arrays in pages are now ordered correctly, matching the checkbox option order

…fields appear on the page to help avoid page skipping weirdness
@wjrm500 wjrm500 force-pushed the bugfix/condition-ordering-causing-skipping branch from c97b8c6 to de6adf8 Compare July 10, 2025 12:03
Copy link

Comment on lines +58 to +65
save = async (toUpdate, callback = () => {}) => {
try {
await this.designerApi.save(this.id, toUpdate);
const sortedData = sortConditionsBySourceFieldOrder(toUpdate);

await this.designerApi.save(this.id, sortedData);
// @ts-ignore
this.setState({data: toUpdate, updatedAt: new Date().toLocaleTimeString(), error: undefined,}, callback());
return toUpdate;
this.setState({data: sortedData, updatedAt: new Date().toLocaleTimeString(), error: undefined,}, callback());
return sortedData;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v unfamiliar with this codebase sorry. Is the broken behaviour coming from XGovFormBuilder, or from something we've layered on top of it?

If it's broken in XGFB and we're patching a fix in here - should we instead be trying to fix it upstream, get that merged, and then pull it in ourselves?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants